package com.example.task1.ui.AllService.word;

import android.os.Bundle;
import android.view.MenuItem;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.viewpager.widget.ViewPager;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.WordJobBean;
import com.example.task1.bean.WordJobListBean;
import com.example.task1.http.Api;
import com.example.task1.util.ApiResp;
import com.example.task1.util.CallBack;
import com.google.android.material.tabs.TabLayout;

import retrofit2.Call;

public class WordJobActivity extends AppCompatActivity {

    private TabLayout tabLayout;
    private ViewPager pager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_word_job);
        ActionBar supportActionBar = getSupportActionBar();
        supportActionBar.setTitle("活动详情");
        supportActionBar.setDisplayHomeAsUpEnabled(true);
        initData();
        initView();

    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
        }
        return super.onOptionsItemSelected(item);
    }

    private void initData() {
        Call<ApiResp> apiRespCall = Api.api().get(MyApplication.TOKEN, "/prod-api/api/job/profession/list");
        Api.send(apiRespCall, WordJobBean.class, new CallBack<WordJobBean>() {
            @Override
            public void success(WordJobBean data) {
                WordJobAdapter wordJobAdapter = new WordJobAdapter(getSupportFragmentManager(),data.getRows());
                pager.setAdapter(wordJobAdapter);
                tabLayout.setupWithViewPager(pager);
            }

            @Override
            public void error(String msg) {

            }
        });

    }

    private void initView() {
        tabLayout = findViewById(R.id.tab_layout);
        pager = findViewById(R.id.pager);
    }
}